<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="充值金额">
        <el-input-number v-model="bankRemit.remitMoney"
                         :precision="2"
                         :step="0.01"
                         controls-position="right"  :min="0.01" ></el-input-number>
      </el-form-item>
      <el-form-item label="付款方式">
        <el-select v-model="bankRemit.bankId" placeholder="请选择付款方式">
          <el-option
            v-for="item in banks"
            :key="item.id"
            :label="item.label"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即充值</el-button>
        <el-button  @click="close()">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getDictByType } from '@/api/dict'
import { topUp } from '@/api/BankRemit'

export default {
  name: 'CustomerTopUp',
  props:{
    id: {
      type: Number,
      default: null
    }
  }
  ,
  data(){
    return{
      bankRemit:{

      },
      banks:[]
    }
  },
  methods:{
    getBankDict(){
      getDictByType("bank_type").then(res=>{
        this.banks=res;
      })
    }
    ,
    close(){
      this.$emit("close");
    },
    onSubmit(){
      topUp(this.bankRemit).then(res=>{
        if (res==0){
          this.$message.error('充值失败!');
        }else {
          this.$message({
            message: '充值成功!',
            type: 'success'
          });
        }
      })
    }
  },
  mounted() {
    this.bankRemit.customerId=this.id;
    this.getBankDict();
  }
}
</script>

<style scoped>

</style>
